<?php

// PHP Default is 30 (seconds)
// if safe mode is enabled, this is useless
//set_time_limit(10000);
set_time_limit(100);

// Host/IP
$host = $_REQUEST['host']; 

// Start Port
$sport = $_REQUEST['sport'];

// End Port
$eport = $_REQUEST['eport'];

if(empty($host) || empty($sport) || empty($eport)) { 
	echo "$host or $sport or $eport is an empty value, aborting script"; exit();
}

$eport++;

for ($current = $sport; $current < $eport; $current++) { 
	echo "Port " . $current . ",";

	// Get the name of the ports service
	$service = getservbyport($current, "tcp");

	// check if we got the default service name for that port
	if ($service) {
		echo " <span class='service'>" . $service . "</span>";
	} else {
		echo "";
	}

	// Try and open the socket
	$result = @fsockopen($host,$current,$errno,$errstr,1);

	// check if successful
	if ($result) {
		echo " is <span class='open'>open</span><br />";
	} else {
		echo " is <span class='closed'>closed</span><br />";
	}
}

?>